﻿@using Piedone.HelpfulLibraries.Utilities

@{
    Style.Include("lombiq-watcher.css");

    Script.Require("jQuery").AtHead();
    Script.Include("lombiq-watcher.js").AtFoot();

    var part = (Lombiq.Watcher.Models.WatchablePart)Model.ContentPart;
}

@if (WorkContext.CurrentUser != null && Authorizer.Authorize(Lombiq.Watcher.Permissions.WatchItems))
{
    var isWatching = part.WatcherIds.Contains(WorkContext.CurrentUser.Id);
    var linkClass = isWatching ? "watching" : "not-watching";
    
    <div class="lombiq-watcher-controls lombiq-watcher-controls-@part.ContentItem.Id">
        <a href="#" data-item-id="@part.ContentItem.Id" class="lombiq-watcher-watch-link @linkClass"><span class="watching-text" title="@T("Unwatch")">@T("Watching")</span><span class="not-watching-text">@T("Watch")</span></a>@* </a> in the same line, otherwise there would be a space till the end of the anchor. *@
        <span class="lombiq-watcher-count">(@part.WatcherIds.Count)</span>
        <span class="lombiq-watcher-error">@T("There was some error, sorry... Please try again later.")</span>
    </div>
}

@using (Script.Foot())
{
    if (this.WasNotDisplayed("Lombiq.Watcher.Init"))
    {
    <script type="text/javascript">
        (function ($) {
            $(function () {
                $.lombiq.watcher.init("@Url.Action("Watch", "Watch", new { Area = "Lombiq.Watcher" })", "@Url.Action("Unwatch", "Watch", new { Area = "Lombiq.Watcher" })");
            });
        })(jQuery);
    </script>
    
    @Html.AntiForgeryToken() // There might not be any antiforgery token on the page, but it's needed for the POST.
    }
}